<?php

/*
 * 	$Id: calender.php  2014-11-03 08:25:00 sbraeutig $
 * 	Copyright (c) 2011-2021 Indiv-Style
 * 	http://www.indiv-style.de
 */

$box_smarty = new smarty;

$box_smarty->caching = false;
$box_smarty->assign('language', $_SESSION['language']);
$box_smarty->assign('html_tpl_path', CURRENT_TEMPLATE . '/html');
$box_smarty->assign('box_name', getBoxName('calender'));
$box_smarty->assign('box_class_name', getBoxCSSName('calender'));
$my_calender = '[';
$badge = 'false';
$calender_query = xtc_db_query("SELECT calender, datestart, dateend FROM blog_items WHERE calender > 0 AND datestart != '0000-00-00'  AND status = '2' AND language_id = '" . (int) $_SESSION['languages_id'] . "' ");
while ($calender = xtc_db_fetch_array($calender_query)) {
    if ($calender['calender'] == 2) {
        $badge = 'true';
    } else {
        $badge = 'false';
    }
    //$datumdif = xtc_db_query("SELECT datediff(".$calender['datestart'].", ".$calender['dateend'].")");
    if ($calender['datestart'] == $calender['dateend'] || $calender['dateend'] == '0000-00-00' || $calender['datestart'] > $calender['dateend']) {
        $my_calender .= '{"date":"' . $calender['datestart'] . '","badge":' . $badge . ',"title":"zum ansehen der Termine klicken!!!"},';
    } else {
        $datetime1 = new DateTime($calender['datestart']);
        $datetime2 = new DateTime($calender['dateend']);
        $interval = $datetime1->diff($datetime2);
        $oldday = $calender['datestart'];
        for ($i = 0; $i <= $interval->days; $i++) {
            $nextDay = strtotime("+" . $i . " day", strtotime($oldday));
            $newday = date("Y-m-d", $nextDay);
            $my_calender .= '{"date":"' . $newday . '","badge":' . $badge . ',"title":"zum ansehen der Termine klicken!!!", classname: "day booben"},';
        }
    }
}
$my_calender .= ']';

$box_smarty->assign('MYCALENDER', $my_calender);
if (!$cache) {
    if (file_exists('templates/' . CURRENT_TEMPLATE . '/boxes/box_calender.html')) {
        $box_content = $box_smarty->fetch(CURRENT_TEMPLATE . '/boxes/box_calender.html');
    } else {
        $box_content = $box_smarty->fetch('base/boxes/box_calender.html');
    }
} else {
    if (file_exists('templates/' . CURRENT_TEMPLATE . '/boxes/box_calender.html')) {
        $box_content = $box_smarty->fetch(CURRENT_TEMPLATE . '/boxes/box_calender.html', $cache_id);
    } else {
        $box_content = $box_smarty->fetch('base/boxes/box_calender.html', $cache_id);
    }
}